home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
forth
/
amiga
/
amigaker.arc
/
07.dos
< prev
next >
Wrap
Text File
|
1988-01-09
|
6KB
|
163 lines
;
; 07.dos
; Support routines for dos, not the regular forth block stuff.
; The dos routines allow two levels of interface, raw and buffered.
; The raw routines are accessable through the low level calls, provided
; by dos. Calls are e.g. Read, Write, Seek. Buffers are assigned by the
; user.
; Buffered file useage is through specific calls to routines:
; getc, putc, gets, puts and ungetc. ( if implemented )
; The buffers are 512 bytes long and are invisible. All operations on
; the files take in-file and file as pointers to file info buffers fib's.
; A fib is:
; 0 long file-handle
; 4 long 'buffer
; 8 word buffersize (default 512, max 32k )
; 10 word flags
; 12 long 'nextchar
; 16 word # char remaining (writing) or # char in the buffer (read)
; 18 long link ( to close files on exit )
; 22 .... name null terminated with preceding size byte, actually not
; part of the fib, but in files declared by file:, the name
; will follow the fib.
;
; flags: bit 0 1=eof
; bit 15 1=dirty 0=clear
;
; All files, whether raw or buffered, have an fib. The raw files do not
; use the information from flags on. The file will be closed if forth is
; exitted. The buffer allocated with Allocmem will be freed up.
; NOTE DO NOT USE BUFFERS LARGER THEN 32K.
; Make four links for dos vocabulary
doslink0 set 0
doslink1 set 0
doslink2 set 0
doslink3 set 0
* dos Vocabulary, coincides with a Library
dc.w -1
dc.l link0
link0 set *-4
dc.b $83,'do',$80!'s'
cnop 0,2
_dos dc.l vocabulary_does
dc.l dosLink0,dosLink1,dosLink2,dosLink3,voc_link
voc_link set *-4
* DosBase (s -- addr ) Holds the DosBase, the Library vector.
dc.w -1
dc.l doslink0
doslink0 set *-4
dc.b $87,'DosBas',$80!'e'
cnop 0,2
_DosBase dc.l docreate
dosbase dc.l 0
dc.l lib_link ;linked list for libraries.
lib_link set *-4
* doscall (s flag offset mask -- ) Creates an entry in the
; dictionary, which calls the Dos library
dc.w -1
dc.l doslink0
doslink0 set *-4
dc.b $87,'doscal',$80!'l'
cnop 0,2
_doscall dc.l nest
dc.l _create,_w_comma,_w_comma,_w_comma
dc.l _nest_semi_colon_code
dosbased move.l dosbase,a0
jmp callrom
* Open-Dos (s -- ) Opens the library, aborts if unable to open.
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $88,'Open-Do',$80!'s'
cnop 0,2
_Open_Dos dc.l nest
dc.l _nest_quote
dc.b 12,'dos.library',0
cnop 0,2
dc.l _drop,_0,_OpenLibrary,_dup,_0_equal
dc.l _nest_abort_quote
dc.b 19,'Unable to open Dos',0
cnop 0,2
dc.l _DosBase,_store,_exit
* Close-Dos (s -- ) Close Dos library
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $89,'Close-Do',$80!'s'
cnop 0,2
_Close_Dos dc.l nest
dc.l _DosBase,_fetch,_DosBase,_off
dc.l _CloseLibrary
dc.l _exit
* Open (s accessMode 'name -- file-handle )
; Calls Dos Lib function Open. Note the order of parameters.
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $84,'Ope',$80!'n'
cnop 0,2
_Open dc.l dosbased
dc.w %110,$ffe2,-1
* Close (s file-handle -- )
; Calls Dos Lib function Close
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $85,'Clos',$80!'e'
cnop 0,2
_Close dc.l dosbased
dc.w %10,$ffdc,0
* Read (s length buffer file -- length )
; Calls Dos Read function. Returns actual bytes read.
dc.w -1
dc.l doslink2
doslink2 set *-4
dc.b $84,'Rea',$80!'d'
cnop 0,2
_Read dc.l dosbased
dc.w %1110,$ffd6,-1
* Write (s length buffer file -- length )
; Dos Write function.
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $85,'Writ',$80!'e'
cnop 0,2
_Write dc.l dosbased
dc.w %1110,$ffd0,-1
* Seek (s mode position file -- oldposition )
; Dos' Seek function.
dc.w -1
dc.l doslink3
doslink3 set *-4
dc.b $84,'See',$80!'k'
cnop 0,2
_Seek dc.l dosbased
dc.w %1110,$ffbe,-1
* IoErr (s -- error )
; Dos' IoErr function, returns integer error number.
dc.w -1
dc.l doslink1
doslink1 set *-4
dc.b $85,'IoEr',$80!'r'
cnop 0,2
_IoErr dc.l dosbased
dc.w %0,$ff7c,-1